package ar.edu.utn.frba.tacs.warnes.rest;

import java.io.IOException;

import ar.edu.utn.frba.tacs.warnes.Auto;
import ar.edu.utn.frba.tacs.warnes.aop.Utils;
import ar.edu.utn.frba.tacs.warnes.excepciones.RestException;
import ar.edu.utn.frba.tacs.warnes.utils.ContenedorWarnes;

import com.thoughtworks.xstream.XStream;


public class AutoResource {
	XStream xstream = new XStream();
	private final String dir = System.getProperties().getProperty("user.dir");


	public String getAutoPorId(Long id) {
		Auto auto = ContenedorWarnes.getInstance().getAutos(id).get(0);
		return this.guardarAuto(auto);
	}


	public String guardarAuto(Auto auto) {
		String xml;
		String ruta = this.dir + "\\rest\\auto\\";
		xml = this.xstream.toXML(auto);
		try {
			Utils.grabarArchivoADisco(ruta, "auto-id=" + auto.getId() + ".xml",
					xml);
		} catch (IOException ex) {
			throw new RestException(ex.getMessage());
		}
		return xml;
	}
}
